/************************************************************************

								Heroes IV
					  Copyright 2002, The 3DO Company

	------------------------------------------------------------------
  					 combat_action_message_displayer.cpp

	$Header:  $

	$NoKeywords: $

 ************************************************************************/
// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "combat_action_message_displayer.h"

#include "battlefield.h"
#include "combat_window.h"

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
t_combat_action_message_displayer::t_combat_action_message_displayer( t_battlefield & battlefield )
	: m_battlefield( battlefield ), m_displaying_message( false )
{
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
t_combat_action_message_displayer::~t_combat_action_message_displayer()
{
	if ( m_displaying_message )
		erase_action_message();
}

// ----------------------------------------------------------------------
// Display a message explaining the current animation or action happening
// on the battlefield. 
// ----------------------------------------------------------------------
void t_combat_action_message_displayer::display_action_message( t_combat_action_message const & message )
{
	if ( m_displaying_message )
		erase_action_message();

	m_message = message;

	t_combat_window * combat_window = m_battlefield.get_combat_window();

	combat_window->display_creature_action( *this, message );
	
	m_displaying_message = true;
}

// ----------------------------------------------------------------------
// Erase the current action message (if held by this displayer) and return
// to displaying stats for the currently selected creature
// ----------------------------------------------------------------------
void t_combat_action_message_displayer::erase_action_message( )
{
	m_message.clear();

	if ( m_displaying_message )
	{
		t_combat_window * combat_window = m_battlefield.get_combat_window();

		// May be null if we are currently in destructors
		if ( combat_window )
			combat_window->end_displayed_creature_action( *this );

		m_displaying_message = false;
	}
}

